﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Media.Imaging;
using System.IO;
using System.IO.IsolatedStorage;
using Microsoft.Xna.Framework.Media;
using com.google.zxing;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Threading;

namespace iLikeWine
{
    public partial class Vinhos : PhoneApplicationPage
    {
        private const string conn = @"isostore:/iLikeWine.sdf";
        Wine w = new Wine();
        public Vinhos()
        {
            InitializeComponent();

            IList<Wine> lista = this.GetWines();


            StringBuilder messageBuilder = new StringBuilder();
            messageBuilder.AppendLine("Vinhos");


            foreach (Wine w in lista)
            {
               
                    messageBuilder.AppendLine("--------------");
                    messageBuilder.AppendLine("Nome: " + w.Nome + "  Ano: " + w.Ano + "  ID: " + w.ID);
                    if (w.Nome.Equals("qw"))
                    {
                        nome.Text = w.Nome;
                        ano.Text = w.Ano;
                        regiao.Text = w.Regiao;
                        tipo.Text = w.Tipo;
                        //--> FOTO
                        image1.DataContext = w.Fotografia;

                        //<-- FOTO
                        //
                        comentario.Text = w.Comentario;
                        
                 }
               

            }
            MessageBox.Show(messageBuilder.ToString());



        }

        public IList<Wine> GetWines()
        {
            IList<Wine> lista = null;
            using (var ctx = new iLikeWineDataContext(conn))
            {
                IQueryable<Wine> query = ctx.Wines;
                //IQueryable<Wine> query = from ctx in ctx.Wines select w ;
                lista = query.ToList();
            }

            return lista;
        }

        private void textBox1_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            
        }
    }
}